package com.amuse.amuse.controller;

import com.amuse.amuse.entity.*;
import com.amuse.amuse.service.impl.CampusPermissionsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RestController
@CrossOrigin
@RequestMapping("/campusManger")
public class CampusPermissionController extends BaseController{
    @Autowired
    private CampusPermissionsServiceImpl campusPermissionsService;
    /*
    * 用户以及管理员发布帖子
    * */
    @PostMapping("/addPosts")
    public ResponseData addPosts(
            String content,
            Integer postId,
            Integer studentId,
            String publishDate
    ){
        return resultObj(campusPermissionsService.addPosts(content,postId,studentId,publishDate) > 0);
    }
    /*
    * 用户及管理员删除发布帖子
    * */

    @PostMapping("/deletePosts")
    public ResponseData deletePosts(
            Integer postId
    ){
        return resultObj(campusPermissionsService.deletePosts(postId) > 0);
    }

    /*
    * 用户及管理员修改帖子
    * */

    @PostMapping("/updatePosts")
    public ResponseData updatePosts(
            String content,
            String publishDate,
            Integer postId
    ){
        return resultObj(campusPermissionsService.updatePosts(content,publishDate,postId) > 0);
    }
    /*
    * 用户及管理员查看自己所发帖子
    * */
    @GetMapping("/findPostsByStudentId")
    public ResponseData<PageBean<campusCirclePosts>> findPostsByStudentId(
            Integer pageNum,
            Integer pageSize,
            Integer studentId
    ){
        PageBean<campusCirclePosts> postsByStudentId = campusPermissionsService.findPostsByStudentId(pageNum, pageSize, studentId);
        return resultObj(postsByStudentId);
    }

    /*
    * 点击查看帖子下面的评论
    * */
    @GetMapping("/findCommentsByPostId")
    public ResponseData<PageBean<postComments>> findCommentsByPostId(
            Integer pageNum,
            Integer pageSize,
            Integer postId
    ){
        PageBean<postComments> postCommentsPostId = campusPermissionsService.findCommentsByPostId(pageNum, pageSize, postId);
        return resultObj(postCommentsPostId);
    }
    /*
    * 查看所有帖子及评论数和点赞数
    * */
    @GetMapping("/findAllPosts")
    public ResponseData<PageBean<campusCirclePosts>> findAllPosts(
            Integer pageNum,
            Integer pageSize
    ){
        PageBean<campusCirclePosts> allPosts = campusPermissionsService.findAllPosts(pageNum, pageSize);
        return resultObj(allPosts);
    }

    /*
    * 学生发表评论
    * */
    @PostMapping("/addComments")
    public ResponseData addComments(
            String content,
            Integer commentId,
            Integer postId,
            Integer studentId,
            String publishDate
    ){
        return resultObj(campusPermissionsService.addComments(content,commentId,postId,studentId,publishDate) > 0);
    }

    /*
    * 用户点赞和取消点赞
    * */
    @PostMapping("/addLikes")
    public ResponseData addLikes(
            Integer likeId,
            Integer postId,
            Integer studentId,
            Boolean status
    ){
        return resultObj(campusPermissionsService.addLikes(likeId,postId,studentId,status) > 0);
    }
    /*
    * 学生删除自己的评论
    *
    * */
    @PostMapping("/deleteComments")
    public ResponseData deleteComments(
            Integer commentId
    ){
        return resultObj(campusPermissionsService.deleteComments(commentId) > 0);
    }
    /*
    * 学生查询自己在帖子下所有的评论
    * */
    @GetMapping("/findCommentsByStudentId")
    public ResponseData<PageBean<postComments>> findCommentsByStudentId(
            Integer pageNum,
            Integer pageSize,
            Integer studentId
    ){
        PageBean<postComments> postCommentsStudentId = campusPermissionsService.findCommentsByStudentId(pageNum, pageSize, studentId);
        return resultObj(postCommentsStudentId);
    }
    /*
    * 学生查看自己的点赞信息
    * */
    @GetMapping("/findLikesByStudentId")
    public ResponseData<PageBean<postLikes>> findLikesByStudentId(
            Integer pageNum,
            Integer pageSize,
            Integer studentId
    ){
        PageBean<postLikes> postLikesStudentId = campusPermissionsService.findLikesByStudentId(pageNum, pageSize, studentId);
        return resultObj(postLikesStudentId);
    }


}
